#!/usr/bin/env bash
wget -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.2-amd64.deb
sudo dkpg -i elasticsearch-7.15.2-amd64.deb
sudo mkdir -p /data/elasticsearch/data
sudo mkdir -p /data/elasticsearch/logs
sudo chown -R elasticsearch:elasticsearch /data/elasticsearch/
sudo sed -i 's%\/var\/lib\/elasticsearch%\/data\/elasticsearch\/data%g' /etc/elasticsearch/elasticsearch.yml
sudo sed -i 's%\/var\/log\/elasticsearch%\/data\/elasticsearch\/logs%g' /etc/elasticsearch/elasticsearch.yml
## 必须设置了集群才能正常的启动。所以单台就下面的设置就好了。多台可以配置多台集群
cat >>/etc/elasticsearch/elasticsearch.yml<<EOF
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0"]
node.master: true
cluster.name: TestCluster
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
EOF
sudo firewall-cmd --zone=public --permanent --add-port=9200/tcp
sudo firewall-cmd --reload
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service